package com.zhiyou.service.impl;

import com.zhiyou.dao.HouseMapper;
import com.zhiyou.dao.LogisticsMapper;
import com.zhiyou.dao.RecordMapper;
import com.zhiyou.entity.House;
import com.zhiyou.entity.Logistics;
import com.zhiyou.entity.Record;
import com.zhiyou.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecordServiceImpl implements RecordService {
    @Autowired
    RecordMapper recordMapper;
    
    @Autowired
    LogisticsMapper logisticsMapper;

    HouseMapper houseMapper;
    
    //得到所有的记录信息
    @Override
    public List<Record> getAllRecord() {
        return recordMapper.selectAllRecord();
    }

    @Override
    public List<Record> getAll2() {
        return null;
    }

    @Override
    public List<Record> selectRecordByHouseRoom(House house) {
        recordMapper.selectRecordByHouseRoom(house);
        return recordMapper.selectRecordByHouseRoom(house);

    }

    @Override
    public List<Logistics> getAllLogistics() {
        System.out.println("service层执行");
        return recordMapper.selectAllLogistic();

    }

    @Override
    public void addRecord(Record record) {
        recordMapper.addRecord(record);
    }

    @Override
    public Logistics getLogisticsByName(String name){
        Logistics logistics = new Logistics();
        logistics.setLoName(name);

        return logisticsMapper.selectOne(logistics);
    }

    @Override
    public House getHouseByHouseRoomno(String roomno) {
        House house = new House();
        house.sethRoomno(roomno);
        return recordMapper.getHouseByHouseRoomno(house);
    }

    @Override
    public Record getRecordById(Integer id) {

        return recordMapper.getRecordById(id);
    }

    @Override
    public void updateRecordById(Record record) {
        System.out.println("运行到此");
        recordMapper.updateRecordById(record);
    }

    @Override
    public List<Record> getRecordsRetimeOrHouseAreaOrLoName(String string) {
        List<Record> records = null;
        //假设通过时间能够查出
        Record record = new Record();
        record.setReTime(string);
        records = recordMapper.getRecordByLikeRecordTime(record);

        if( records.size()==0){
            System.out.println("根据房屋地址查询");
            //再假设通过房屋地址能够查出
            House house = new House();
            house.sethArea(string);
            records=recordMapper.getRecordByLikehouseArea(house);

        }

        if( records.size()==0){
            System.out.println("根据后勤人员查询");
            //可能通过后勤人员能查出来
            Logistics logistics=new Logistics();
            logistics.setLoName(string);
            records = recordMapper.getRecordByLikeloName(logistics);

        }
        return records;
    }

    @Override
    public void deleteRecordById(Record record) {
        recordMapper.deleteRecordById(record);
    }


}
